package com.auhaix.common;

import com.auhaix.common.Response;
import com.auhaix.common.ResponseUtils;
import com.auhaix.common.UserException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: Auhaix
 * E-mail: xh@qiandw.com
 * Description:
 * CreatedTime: 2017/8/3 13:56
 * Modified by:
 */
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Response handle(Exception e) {
        if (e instanceof UserException) {
            UserException userException = (UserException) e;
            return ResponseUtils.error(userException.getMsgCode(), userException.getMessage());
        } else {
            return ResponseUtils.error("-1", "未知错误");
        }
    }
}
